package com.ebelter.myehc.ui.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.myehc.R;


/**
 * Created by ZCQ on 2017/12/1
 * 组合控件1 不知道怎么起名字了 还是按序号来吧
 */

public class CombinView4 extends LinearLayout{
    public CombinView4(Context context) {
        this(context,null);
    }




    public CombinView4(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }




    public CombinView4(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CombinView4);
        if (typedArray != null) {
            title1 = typedArray.getString(R.styleable.CombinView4_title1);
            drawable = typedArray.getDrawable(R.styleable.CombinView4_image1);
            typedArray.recycle();
        }

        initView(getContext());


    }

    private String title1;
    private Drawable drawable;


    private TextView title1_tv;
    private ImageView image_iv;



    private void initView(Context context) {
        View view =  View.inflate(context, R.layout.cb4_layout, this);//把那个布局当做是自己的孩子

        title1_tv = view.findViewById(R.id.cb4_title1);
        image_iv = view.findViewById(R.id.cb4_iv1);
        setTitle1(title1);
        image_iv.setImageDrawable(drawable);


    }



    public void setSize(int sp){
        ViewUtils.setTextSize(title1_tv,sp);
    }


    public void setTitle1(String title1){
        this.title1=title1;
        if (title1_tv!=null){
            title1_tv.setText(this.title1);
        }
    }

    public void setImage(int res){
        if (image_iv!=null){
            image_iv.setImageResource(res);
        }
    }

}
